﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mengoo.BDMTier;
using Mammoo.WebServer.Model;
using Mengoo.DB;
using Mammoo.WebServer.DAL;
using System.Data;

namespace Mammoo.WebServer.BLL
{
    public class MemberService:Service
    {
        new public MemberDao dao = new MemberDao();

        /// <summary>
        /// 实例化
        /// </summary>
        public MemberService()
        {
            base.dao = dao;
        }

        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Register(MemberInfo model)
        {
            model.Member_ID = Guid.NewGuid();

            int result = dao.Add(model);
            if (result > 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public MemberInfo Login(string userName, string password)
        {
            return dao.Login(userName, password);
        }

        /// <summary>
        /// 根据用户名或邮箱检查是否存在用户记录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public bool Validate(string username,string email)
        {
            DataTable dt = dao.GetMemberID(username, email);
            if (dt.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
    }
}
